/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jeck.action.cu_evento.ver.data;

import com.jeck.action.cu_loginadmin.data.mg_Login;
import com.jeck.conexion.Conector;
import com.jeck.tools.Event;
import com.jeck.tools.Menu;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author bicho
 */
public class Mg_ShowEvent {
    public static Event getEventoData(int id){
        Conector cn = new Conector();        
        Event ev = null;
        ResultSet rs = cn.Consultar("SELECT *  FROM evento_especifico WHERE id_evento='"+id +"' ; ");
        try {
            while (rs.next()) {
                ev = new Event(rs.getString("nombre"), rs.getString("descripcion"), id);
            }
        } catch (SQLException ex) {
            Logger.getLogger(mg_Login.class.getName()).log(Level.SEVERE, null, ex);
        }        
        return ev;
    }
    public static List getMenuByIdUser(int id) {
        System.out.println("accediendo getMenuByIdUser");
        Conector cn = new Conector();
        List menu = new ArrayList();
        ResultSet rs;
        if(id>0){
                rs = cn.Consultar("SELECT M.nombre FROM usuario U inner join " +
                "rol R on U.id_rol = R.id_rol inner join menu_rol N on " +
                "R.id_rol = N.id_rol inner join menu M on N.id_menu = M.id_menu " +
                "WHERE id_usuario = "+ id +";");
        }else{
               rs = cn.Consultar("SELECT M.nombre FROM rol R inner join menu_rol" +
                       " N on R.id_rol = N.id_rol inner join menu M on " +
                       "N.id_menu = M.id_menu WHERE R.id_rol = 4;");
        }

        try {
            while (rs.next()) {
                System.out.println("añadido :"+rs.getString(1));
                Menu m = new Menu(rs.getString("descripcion"), rs.getString("descripcion").replace(" ", "")+".action");
                menu.add(m);
            }
        } catch (SQLException ex) {
            Logger.getLogger(mg_Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        return menu;
    }
}
